package com.zzptc.easyshop.dao;

import com.zzptc.easyshop.db.IDB;
import com.zzptc.easyshop.db.MysqlDB;
import com.zzptc.easyshop.facory.DaoFacoryImp;
import com.zzptc.easyshop.vo.Good;
import com.zzptc.easyshop.vo.VO;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

public class ProductDao implements IDAO {
    @Override
    public boolean insert(VO vo) throws SQLException {
        return false;
    }

    @Override
    public boolean login(VO vo) throws SQLException {
        return false;
    }

    @Override
    public List getAll() throws SQLException {
        List list = new ArrayList();
        //获取数据库连接
        IDB db = new MysqlDB();
        Connection conn = db.getConn();
        //获取工具类
        PreparedStatement ps = conn.prepareStatement("select * from easybuy_product_category");
        ResultSet rs = ps.executeQuery();
        while (rs.next()) {
            Good good = new Good();
            good.setEpc_id(rs.getInt(1));
            good.setEpc_name(rs.getString(2));
            good.setEpc_parent_id(rs.getInt(3));
            list.add(good);
        }

        return list;
    }

    public static void main(String[] args) throws Exception {
        List list = new ArrayList();
        ProductDao dao = (ProductDao) DaoFacoryImp.getInstance().createDAO("productdao");
        try {

            list = dao.getAll();
            System.out.println(list.size());
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
